package com.fuluwa.domain.order.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;

import com.fuluwa.domain.product.model.Product;
import com.fuluwa.domain.shared.AbstractIdDomainObject;

@Entity
@Table(name="t_order_item")
public class OrderItem extends AbstractIdDomainObject {

    private static final long serialVersionUID = -2779628405300989644L;

    @ManyToOne
    @ForeignKey(name="null")
	private Product product;
	@ManyToOne
	@ForeignKey(name="null")
	private Order order;
	@Column(name = "t_price", columnDefinition = "decimal(13,2)")
	private double price;		//单价

	private int quantity;

	private String itemInfo;    //保存产品详细信息，例如：名称+颜色+尺码等等

	private String remark;
	
	private OrderItem() {
	}

	public OrderItem(Product product, int quantity, String itemInfo, String remark) {
		this.product = product;
		this.quantity = quantity;
		this.itemInfo = itemInfo;
		this.remark = remark;
		this.price=product.getPrice();
	}

	public Product getProduct() {
		return product;
	}

	public Order getOrder() {
		return order;
	}

	public double getPrice() {
		return price;
	}

	public int getQuantity() {
		return quantity;
	}

	public String getItemInfo() {
		return itemInfo;
	}

	public String getRemark() {
		return remark;
	}

	public void updateOrder(Order order) {
		this.order = order;
	}


   /* public void setOrderInfoByCartItem(CartItem cartItem){
    	this.product = cartItem.getProduct();
    	this.itemInfo = cartItem.getItemInfo();
    	this.quantity = cartItem.getQuantity();
    	this.price = cartItem.getProductPrice();	//获得产品单价
    }*/
}
